<?php
class TopController  extends Controller {

	public function __construct($data) {
        parent::__construct($data);
    }
	
public function index() {
	    require_once( '../system/ecjp_m.php' );
	    $this->_load_php_file("chklogin.php");
	    if(!isset($_SESSION['USER'])){
	    	
	    require_once( '../system/cookie.php' );
	    
	    }
	        
	    $this->_load_php_file("Class_FUNC.php");
	    $goodsset = Class_FUNC::get_goodsset();
	    
	    $site = Class_FUNC::get_site();
	    if(isset($site['site_keyword']))
	    $this->assign('site_keyword', $site['site_keyword']);
        if(isset($site['site_description']))
	    $this->assign('site_description', $site['site_description']);
	    if(isset($site['site_title']))
	    $this->assign('site_title', $site['site_title']);
	    
	    $this->_load_mdao_class("t_m_goods");
	    $goods_dao = new t_m_goods;
	    
	    $this->_load_mdao_class("t_m_news");
	    $news_dao = new t_m_news;
	     
	     //NEWS message
	     $sql = 'SELECT * FROM  m_news  where site_id = 1 order by date desc limit 0,1'; 
	     $news_data = $news_dao->get_rows($sql);
	     if (isset($news_data))
	     $this->assign('news_data', $news_data[0]);
	     
	     
         //
         $wherearr = array();
         $wherearr[] = sprintf("(a.goods_mark1= '%s' and a.goods_status= '%s'  )",'1','1');
	     $anni_data = $goods_dao->search_csv($wherearr);
	       

	       foreach ($anni_data as &$value){
	          if(isset($value['goods_image']) && !empty($value['goods_image'])){	     	
	     	$value['goods_image'] = Class_FUNC::get_imagepath($value['id'],$value['goods_image'],1);
	       }
	        if(isset($value['goods_unitprice']) && !empty($value['goods_unitprice'])){
	          	 $value['goods_rate'] = $value['goods_unitprice']+$value['goods_unitprice'] * RATE;
	          }
	     }
	     
	     
	     if (isset($anni_data))
	     $this->assign('anni_data', $anni_data);
	     
	     	     
	     //
	       $sql = "SELECT * FROM `d_goods` WHERE  goods_mark1='1' order by sellbegin desc LIMIT 0,10";
	       $charts_data = $goods_dao->get_rows($sql);
	        foreach ($charts_data as &$value){
	          if(isset($value['goods_image']) && !empty($value['goods_image'])){
	     	     $value['goods_image'] = Class_FUNC::get_imagepath($value['id'],$value['goods_image'],1);
	       }
	        if(isset($value['goods_unitprice']) && !empty($value['goods_unitprice'])){
	          	 $value['goods_rate'] = $value['goods_unitprice']+$value['goods_unitprice'] * RATE;
	          }
	         
	     }     
	       if (isset($charts_data))
	       $this->assign('charts_data',$charts_data);
	     
	     //What's New
           $sql = 'SELECT * FROM  m_news where site_id = 1 order by date desc limit 0,10';
           $newslist_data = $news_dao->get_rows($sql);
           if (isset($newslist_data))
           $this->assign('news_datalist', $newslist_data);
	     
	     //category
	       $sql = 'SELECT * FROM  m_categorygood';
           $category_data = $goods_dao->get_rows($sql);
           if (isset($category_data))
           $this->assign('category_data', $category_data);

         $this->assign('pc_head', $this->fetch('pc/pc_head.html'));
         $this->assign('pc_foot', $this->fetch('pc/pc_foot.html'));
         $this->assign('categorying', $this->fetch('pc/categorying.html'));
         $this->assign('newsing', $this->fetch('pc/news.html'));
	     $this->assign('chartsing', $this->fetch('pc/charts.html'));
	     $this->display('pc/index.html');
	}
    
}